package com.keyancompany.zhongbaopingtai.activity;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.keyancompany.zhongbaopingtai.Constants;
import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.api.CircleAPI;
import com.keyancompany.zhongbaopingtai.model.BaseModel;
import com.keyancompany.zhongbaopingtai.model.CircleDetailModel;
import com.keyancompany.zhongbaopingtai.utils.IntentUtils;
import com.keyancompany.zhongbaopingtai.weight.NoScorllGridView;

import java.lang.reflect.Member;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 圈子详情
 */
public class CirlcleDetailActivity extends BaseActivity {


    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.circle_name)
    TextView circleName;
    @Bind(R.id.circle_kouhao)
    TextView circleKouhao;
    @Bind(R.id.circle_create_time)
    TextView circleCreateTime;
    @Bind(R.id.circle_creator)
    TextView circleCreator;
    @Bind(R.id.circle_desc)
    TextView circleDesc;
    @Bind(R.id.circle_manager)
    TextView circleManager;
    @Bind(R.id.circle_member)
    TextView circleMember;
    @Bind(R.id.go_circle)
    Button goCircle;

    CircleDetailModel detailModel;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_cirlcle_detail;
    }

    @Override
    protected int getMenuId() {
        return 0;
    }

    @Override
    protected void initToolBar() {
        initToolBar(toolbar, "圈子详情");
    }

    @Override
    protected void setUpViews() {

        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                IntentUtils.startActivity(mContext, PublishCircleThemeActivity.class);
                return false;
            }
        });


        CircleAPI.getCircleAllInfo(getIntent().getStringExtra("id"), this, getLoading(-1));
    }

    @Override
    public void success(int type, String json) {
        super.success(type, json);
        BaseModel base = validateJson(json);
        if (base.isSuccess()) {
            detailModel = JSONObject.parseObject(base.data, CircleDetailModel.class);
            setData(detailModel);
        }
    }

    public void setData(CircleDetailModel data) {
        circleName.setText(data.getCircle().getCirclename());
        circleKouhao.setText(data.getCircle().getKouHao());
        circleCreateTime.setText(data.getCircle().getCreateTime());
        circleCreator.setText(data.getUser().getUsername());
        circleDesc.setText(data.getCircle().getCircleinfo());
        circleManager.setText(data.getCircle().getCircleadminmax() + "人");
        circleMember.setText(data.getCircle().getCircleuser() + "人");

//        gridviewManager.setAdapter();
    }

    @OnClick(R.id.circle_manager_parent)
    public void goManagerDetail(View v) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(Constants.TEAM_ID, detailModel.getCircle().getPid());
        bundle.putString("res", "manager");
        IntentUtils.startActivity(this, CircleMemberActivity.class, bundle);
    }

    @OnClick(R.id.go_circle)
    public void setGoCircle(View view) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(Constants.TEAM_ID, detailModel.getCircle().getPid());
        bundle.putString("res", "manager");
        IntentUtils.startActivity(this, CircleThemeActivity.class, bundle);
    }

    @OnClick(R.id.circle_member_parent)
    public void goMemberDetail(View v) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(Constants.TEAM_ID, detailModel.getCircle().getPid());
        bundle.putString("res", "member");
        IntentUtils.startActivity(this, CircleMemberActivity.class, bundle);
    }

}
